package com.kaishengit.service;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.kaishengit.pojo.Document;
import com.kaishengit.pojo.Project;
import com.kaishengit.pojo.User;
import com.kaishengit.util.CreateTime;
import com.kaishengit.util.MyUUID;
import com.kaishengit.util.Outtime;

@Service
@Transactional
public class DocumentService  extends BaseService{
	
	public List<Document> findAllByPro(Project project){
		List<Document> documentList=getDocumentDao().findAllByPro(project);
		for (int i = 0; i < documentList.size(); i++) {
			documentList.get(i).setOuttime(
					Outtime.OutDateTime(documentList.get(i).getCreatetime()));
		}
		return documentList;
	}
	
	public Document finById(String id){
		Document doc= getDocumentDao().findById(id);
		doc.setOuttime(Outtime.OutDateTime(doc.getCreatetime()));
		return doc;
	}
	public void save(Document document,Project project,User user){
		document.setId(MyUUID.createUUID().toString());
		document.setCreatetime(CreateTime.createTime());
		document.setProject(project);
		document.setUser(user);
		
		getDocumentDao().save(document);
	}
	public void update(Document document,String id){
		Document doc=getDocumentDao().findById(id);
		doc.setContent(document.getContent());
		doc.setTitle(document.getTitle());
		getDocumentDao().update(doc);
	}

	public void del(String id) {
		getDocumentDao().del(id);
		
	}
	public List<Document> pageDoc(){
		return getDocumentDao().findByPage(0, 3);
		
	}

}
